package com.dawan.sbjy.Rabbit;

import com.dawan.sbjy.dao.UserDao;
import com.dawan.sbjy.service.impl.MailServiceImpl;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
@RabbitListener(queues ="lile")
public class LileConsumer {
    @Autowired
    MailServiceImpl mailServiceImpl;
    @Autowired
    UserDao userdao;
    @Value("${spring.mail.username}")
    private String from;
    @RabbitHandler
    public void process(String toemail) {
        String emailcode=Integer.toString((int)(Math.random()*9+1)*100000);
        mailServiceImpl.sendSimpleMail(toemail,"注册成功", emailcode);
        //将验证码持久化到数据库中
        userdao.savecode(toemail,emailcode);
        System.out.println("接收处理邮箱队列当中的消息： " + toemail);
    }
}
